﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace XNA_TD.Menue
{
    class GeschwindigkeitsMenue : GUI
    {
        List<Tuple<Rectangle, Texture2D>> knoepfe = null;
        int selected;

        public GeschwindigkeitsMenue()
        {
            Rectangle start = new Rectangle(
                10,
                graphics.GraphicsDevice.Viewport.Height - 50 - 10,
                50,
                50);

            knoepfe = new List<Tuple<Rectangle, Texture2D>>(3);
            if (schwierigkeit != Schwierigkeit.Schwer)
            {
                knoepfe.Add(new Tuple<Rectangle, Texture2D>(start, Content.Load<Texture2D>("Menue/P")));
                start.X += 60;
            }
            selected = knoepfe.Count;
            knoepfe.Add(new Tuple<Rectangle, Texture2D>(start, Content.Load<Texture2D>("Menue/F")));
            start.X += 60;
            knoepfe.Add(new Tuple<Rectangle, Texture2D>(start, Content.Load<Texture2D>("Menue/FF")));

            size = new Rectangle(
                10,
                graphics.GraphicsDevice.Viewport.Height - 50 - 10,
                start.X + 60,
                50);
        }

        public override void Resize()
        {
            var neueKnoepfe = new List<Tuple<Rectangle, Texture2D>>(knoepfe.Count);
            size.Y = graphics.GraphicsDevice.Viewport.Height - 50 - 10;
            foreach (var knopf in knoepfe)
            {
                neueKnoepfe.Add(new Tuple<Rectangle, Texture2D>(new Rectangle(knopf.Item1.X, size.Y, knopf.Item1.Width, knopf.Item1.Height), knopf.Item2));
            }
            knoepfe.Clear();
            knoepfe = neueKnoepfe;
        }

        public override void MouseClick()
        {
            var mouseState = Mouse.GetState();
            for (int i = 0; i < knoepfe.Count; i++)
            {
                if (mouseState.X > knoepfe[i].Item1.X &&
                    mouseState.X < knoepfe[i].Item1.X + knoepfe[i].Item1.Width &&
                    mouseState.Y > knoepfe[i].Item1.Y &&
                    mouseState.Y < knoepfe[i].Item1.Y + knoepfe[i].Item1.Height)
                {
                    if (schwierigkeit == Schwierigkeit.Schwer)
                    {
                        gameSpeed = i + 1;
                    }
                    else
                    {
                        gameSpeed = i;
                    }
                    selected = i;
                }
            }
        }

        public override void Draw()
        {
            var depthStencilState = graphics.GraphicsDevice.DepthStencilState;
            spriteBatch.Begin();
            int id = 0;
            foreach (var knopf in knoepfe)
            {
                if (id == selected)
                {
                    spriteBatch.Draw(knopf.Item2, knopf.Item1, Color.Green);
                }
                else
                {
                    spriteBatch.Draw(knopf.Item2, knopf.Item1, Color.White);
                }
                id++;
            }
            spriteBatch.End();
            graphics.GraphicsDevice.DepthStencilState = depthStencilState;
        }
    }
}
